
# 2337. 移动片段得到字符串

def canChange(start, target):
    i = 0
    j = 0
    length = len(start)
    while i < length and j < length:
        while i < length and start[i] == "_":
            i = i + 1
        while j < length and target[j] == "_":
            j = j + 1
        if i < length and j < length:
            if start[i] != target[j]:
                return False
            if start[i] == "L" and j > i:
                return False
            elif start[i] == "R" and i > j:
                return False
            i = i + 1
            j = j + 1
    while i < length:
        if start[i] != "_":
            return False
        i = i + 1
    while j < length:
        if target[j] != "_":
            return False
        j = j + 1
    return True

if __name__ == "__main__":
    start = "_L__R__R_"
    target = "L______RR"
    print(canChange(start,target))